<!--需要查询到的个人标签数据，个人信息数据-->
<!--准备修改成右侧侧边栏-->
<div id="userInfo" style="display: none">

<div id="otherUserInfo" style="display: none">
<div id="infoShow">
    {% for key,value in userdata.items %}
    <hr>
    {% if key == '个人标签' %}
    <dl id="mylabel" class="col-12" style="display: flex;flex-wrap: wrap"><dt class="col-2" >{{key}}</dt>
        {% for label in value %}
        <dd class="alert alert-primary">{{label}}</dd>
        {% endfor %}
    </dl>
    <div class="col-12" style="text-align: center">
        <input id="labeltxt" class="form-control col-3" type="text" placeholder="标签名" style="visibility:hidden;display: inline-block">
        {% csrf_token %}
        <button id="addLabelBtn" class="btn btn-primary col-3" onclick="addlabel()" type="button" style="line-height: 15px">添加标签+</button>
        <button id="canelAdd" class="btn btn-danger col-3" onclick="canelAdd()" type="button" style="line-height: 15px;visibility:hidden">取消</button>
    </div>
    {% else %}
    <dl class="col-12" style="display: flex"><dt class="col-2">{{key}}</dt><dd class="col-8">{{value}}</dd></dl>
    {% endif %}
    {% endfor %}
</div>
<div id="infoEdit" style="display:none">
    {% for key,value in userdata.items %}
    <hr>
    {% if key == '个人标签' %}
    <dl class="col-12" style="display: flex"><dt class="col-2" style="margin-right: 50px">{{key}}</dt>
        {% for label in value %}
        <dd class="alert alert-primary">{{label}}</dd>

        {% endfor %}
    </dl>
    {% else %}
    <dl class="col-12" style="display: flex"><dt class="col-2">{{key}}</dt><dd class="col-8">{{value}}</dd></dl>
    {% endif %}
    {% endfor %}
</div>
</div>
</div>
<script>
    function addlabel(){
        if(addstatus===0) {
            $("#labeltxt,#canelAdd").css('visibility', 'visible')
            $("#addLabelBtn").text('确认添加').className='btn btn-success'
            addstatus = 1
        }
        else {
            if(!$("#labeltxt").val()){
                message("请输入要添加的标签文本")
            }
            else {
                var txtnode=$("#labeltxt")
                $.ajax(
                    {
                        url:"{% url 'addlabel' %}",
                        data:{'label':txtnode.val(),csrfmiddlewaretoken:'{{csrf_token}}'},
                        datatype:'json',
                        type:'post',
                        success:function (data) {
                            console.log(data.status)
                            if(data.status === 'OK'){
                                popMessage('添加成功')
                                $("#mylabel").append(" <dd class=\"alert alert-primary\">"+txtnode.val()+"</dd>")
                                txtnode.val("")
                            }
                        }
                    }
                )
                $("#labeltxt,#canelAdd").css('visibility', 'hidden')
                $("#addLabelBtn").text('添加标签+').className='btn btn-primary'

            }
        }
    }
    function canelAdd() {
        $("#labeltxt,#canelAdd").css('visibility', 'hidden')
        $("#addLabelBtn").text('添加标签+').className='btn btn-primary'
        addstatus=0
    }
</script>